
# @target:  hello
# @input: files main.o a.o
# @cmd: gcc -o target_name（目标文件，或者PHONY） input_files（依赖目标）
# 执行顺序是  main.o -> a.o -> hello 
# 变量 
#定义变量 make 自动归纳所有.o 文件 
# 2.6 Another Style of Makefile
# When the objects of a makefile are created only by implicit rules, 
# an alternative style of makefile is possible. In this style of makefile,
# you group entries by their prerequisites instead of by their targets.
# Here is what one looks like:
 
C_SRC_PATh = src

C_SRC = src/main.c src/a.c
 
C_INC_PATH = inc

C_INC = inc/a.h inc/main.h 
 
BUILD_PATH = build

C_OBJ = $(BUILD_PATH)/main.o $(BUILD_PATH)/a.o

TARGET = hello 

# 依赖创建目录和编译 .c
$(TARGET):$(BUILD_PATH) $(C_OBJ)
	gcc -o $(BUILD_PATH)/$(TARGET) $(C_OBJ)

# 创建build目录
$(BUILD_PATH):
	mkdir $(BUILD_PATH)

#编译.c
$(C_OBJ):$(C_INC)  
	gcc -c $(C_SRC_PATh)/main.c  -I$(C_INC_PATH) -o $(BUILD_PATH)/main.o
	gcc -c $(C_SRC_PATh)/a.c  -I$(C_INC_PATH) -o $(BUILD_PATH)/a.o 
	
.PHONY:clean
clean : 
	rm -rf $(BUILD_PATH) 